package net;

import java.io.*;
import java.net.Socket;

public class MyClient {
    public static void main(String[] args) {
        Socket socket = null;
        InputStream in = null;
        BufferedReader reader = null;
        OutputStream out = null;

        try {
            socket = new Socket("192.168.0.187", 9999);
            System.out.println("客户端连接成功");

            out = socket.getOutputStream();
            out.write("九江学院".getBytes());
            out.write("\n".getBytes()); // 发送结束标志
            socket.shutdownOutput();

            //接收服务端信息
            in = socket.getInputStream();
            reader = new BufferedReader(new InputStreamReader(in));
            String str = null;
            while ((str = reader.readLine()) != null) {
                System.out.println("客户端接受到服务器的信息是:" + str);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (out != null)
                    out.close();
                if (in != null)
                    in.close();
                if (socket != null)
                    socket.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
